nanopyx.methods.channel_registration
1from .estimator import ChannelRegistrationEstimator 2from .corrector import ChannelRegistrationCorrector 3from ...core.utils.timeit import timeit 4 5@timeit 6def estimate_channel_registration(image_array, ref_channel, max_shift, blocks_per_axis, min_similarity, method="subpixel", 7 save_translation_masks=True, translation_mask_save_path=None, algorithm="field", 8 save_ccms=False, ccms_save_path=False, apply=True): 9 """ 10 Function used to estimate shift between different color channels and align them of an image based on cross correlation. 11 :param image_array:numpy array with shape (n_channels, y, x); image to be corrected 12 :param ref_channel: int; channel index to be used as reference 13 :param max_shift: int; maximum shift accepted for correction, in pixels. 14 :param blocks_per_axis: int; number of blocks to divide the image in both x and y dimensions 15 :param min_similarity: float; minimum value of similarity to accept a shift as a correction 16 :param method: str; "subpixel" (default) or "max"; subpixel uses a minimizer to find the maximum correlation with 17 subpixel precision, max simply takes the maximum of the cross correlation map 18 :param save_translation_masks: bool, defaults to True; whether to save translation masks as a tif or not 19 :param translation_mask_save_path: str; path where to save translation masks 20 :param save_ccms: bool, defaults to True; whether to save cross correlation matrices as a tif or not 21 :param ccms_save_path: str; path where to save cross correlation matrices 22 :param apply: bool; whether to apply the correction if True or only estimate if False 23 :return: if apply==True, returns corrected image with shape (c, y, x) 24 """ 25 estimator = ChannelRegistrationEstimator() 26 aligned_image = estimator.estimate(image_array, ref_channel, max_shift, blocks_per_axis, min_similarity, method=method, 27 save_translation_masks=save_translation_masks, translation_mask_save_path=translation_mask_save_path, 28 save_ccms=save_ccms, ccms_save_path=ccms_save_path, algorithm=algorithm, apply=apply) 29 30 if aligned_image is not None: 31 return aligned_image 32 else: 33 pass 34 35@timeit 36def apply_channel_registration(image_array, translation_masks=None): 37 """ 38 Function used to align different color channels of an image based on cross correlation. 39 :param image_array: numpy array with shape (n_channels, y, x); image to be registered 40 :param translation_masks: numpy array of translation masks 41 :return: returns corrected image with shape (c, y, x) 42 """ 43 corrector = ChannelRegistrationCorrector() 44 aligned_image = corrector.align_channels(image_array, translation_masks=translation_masks) 45 46 return aligned_image
def
estimate_channel_registration(*args, **kwargs):
8 def wrapper(*args, **kwargs): 9 t = time.time() 10 retval = func(*args, **kwargs) 11 print(f"{func.__name__} took {round(time.time()-t,3)} seconds") 12 return retval
Function used to estimate shift between different color channels and align them of an image based on cross correlation.
Parameters
- image_array: numpy array with shape (n_channels, y, x); image to be corrected
- ref_channel: int; channel index to be used as reference
- max_shift: int; maximum shift accepted for correction, in pixels.
- blocks_per_axis: int; number of blocks to divide the image in both x and y dimensions
- min_similarity: float; minimum value of similarity to accept a shift as a correction
- method: str; "subpixel" (default) or "max"; subpixel uses a minimizer to find the maximum correlation with subpixel precision, max simply takes the maximum of the cross correlation map
- save_translation_masks: bool, defaults to True; whether to save translation masks as a tif or not
- translation_mask_save_path: str; path where to save translation masks
- save_ccms: bool, defaults to True; whether to save cross correlation matrices as a tif or not
- ccms_save_path: str; path where to save cross correlation matrices
- apply: bool; whether to apply the correction if True or only estimate if False
Returns
if apply==True, returns corrected image with shape (c, y, x)
def
apply_channel_registration(*args, **kwargs):
8 def wrapper(*args, **kwargs): 9 t = time.time() 10 retval = func(*args, **kwargs) 11 print(f"{func.__name__} took {round(time.time()-t,3)} seconds") 12 return retval
Function used to align different color channels of an image based on cross correlation.
Parameters
- image_array: numpy array with shape (n_channels, y, x); image to be registered
- translation_masks: numpy array of translation masks
Returns
returns corrected image with shape (c, y, x)